<template>
  <div style="display: flex;flex-direction: column">
    <Snackbar title="测试页面"/>
    <van-button type="default" @click="getUserAgent">当前手机系统</van-button>
    <van-button type="default" @click="getAppToken">获取Token</van-button>
    <van-button type="primary" @click="finish">关闭当前页面</van-button>
    <van-button type="danger" @click="loginOut">回到登录页</van-button>
    <van-button type="danger" @click="getUserInfo1">获取系统信息</van-button>
    <van-button type="info" @click="getUserInfo2">获取手机GPU信息</van-button>
  </div>
</template>

<script>
  import {
    getUserAgent,
    getAppToken,
    finish,
    loginOut,
  } from '@/utils/app'
  import { Toast } from 'vant'

  export default {
    name: 'index'
    , methods: {
      getUserAgent() {
        Toast(getUserAgent())
      },
      getAppToken() {
        let token = getAppToken()
        Toast('token=' + token)
      },
      finish() {
        finish()
      },
      loginOut() {
        loginOut()
      },
      getUserInfo1() {
        let u = navigator.userAgent
        let userAgent = getUserAgent()
        let version = ''
        if (userAgent == 'ios') {
          // ios
          let regStr_saf = /OS [\d._]*/gi
          let verinfo = u.match(regStr_saf)
          version = 'IOS' + (verinfo + '').replace(/[^0-9|_.]/ig, '').replace(/_/ig, '.')
        } else if (userAgent == 'android') {
          // android
          version = 'Android' + u.substr(u.indexOf('Android') + 8, u.indexOf(';', u.indexOf('Android')) - u.indexOf('Android') - 8)
        } else if (u.indexOf('BB10') > -1) {
          // 黑莓bb10系统
          version = 'blackberry' + u.substr(u.indexOf('BB10') + 5, u.indexOf(';', u.indexOf('BB10')) - u.indexOf('BB10') - 5)
        } else if (u.indexOf('IEMobile') > -1) {
          // windows phone
          version = 'winphone' + u.substr(u.indexOf('IEMobile') + 9, u.indexOf(';', u.indexOf('IEMobile')) - u.indexOf('IEMobile') - 9)
        } else {
          userAgent = navigator.userAgent.toLowerCase()
          if (userAgent.indexOf('windows nt 5.0') > -1) {
            version = 'Windows 2000'
          } else if (userAgent.indexOf('windows nt 5.1') > -1 || userAgent.indexOf('windows nt 5.2') > -1) {
            version = 'Windows XP'
          } else if (userAgent.indexOf('windows nt 6.0') > -1) {
            version = 'Windows Vista'
          } else if (userAgent.indexOf('windows nt 6.1') > -1 || userAgent.indexOf('windows 7') > -1) {
            version = 'Windows 7'
          } else if (userAgent.indexOf('windows nt 6.2') > -1 || userAgent.indexOf('windows 8') > -1) {
            version = 'Windows 8'
          } else if (userAgent.indexOf('windows nt 6.3') > -1) {
            version = 'Windows 8.1'
          } else if (userAgent.indexOf('windows nt 6.2') > -1 || userAgent.indexOf('windows nt 10.0') > -1) {
            version = 'Windows 10'
          } else {
            version = 'Unknown'
          }
        }
        Toast(version)
      },
      getUserInfo2() {
        let canvas = document.createElement('canvas'),
          gl = canvas.getContext('experimental-webgl'),
          debugInfo = gl.getExtension('WEBGL_debug_renderer_info')
        Toast(gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL))
      },
    }
  }
</script>

<style scoped>

</style>
